<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars 
define("PRIMARY_KEY","services_id");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_transaction_serviceslist_dn.php";
$FileTemplate  = "ais_transaction_serviceslist_dn_list.html";

$PageSize      = 20 ;
$TableName     = "tblservices";
$HTMLGridList  = "ServicesGrid";

//************ FORM ACTION **************
	if (GetParam("Action","")=="Delete") {
		DeleteRecord ("txtCheck",$PageSize);
	}

$curr = GetParam("curr","");
$jo_id = GetParam("jo_id","");
$debtur = GetParam("debtur","");
$debtur_fin = GetParam("debtur_fin","");

$PreserveGet = GetQueryString("All", array("PageNum"));
//Initiate Database Table For Search;
$FNama = GetParam("nameSearch","");
$FCode = GetParam("codeSearch","");

$temp_no_urut = GetParam("no_urut","");

if(!empty($temp_no_urut))
{
  $no_urut = GetParam("no_urut","");
}
else
{
   $no_urut = "";	 
}


//Get Tax Rate

$SQLTaxSel = "SELECT * FROM tbltaxrate WHERE tax_id ='".GetParam("inc_ppn","")."' ";
$ResultTaxSel = $DBConnection->dbc->get_results($SQLTaxSel,ARRAY_A);

$taxRateSel = $ResultTaxSel[0]['calculate']."-".$ResultTaxSel[0]['tax_kind'];

//End Get Tax Rate



$FormName = GetParam("FormName","");
//******* DATABASE FORM QUERY ***********

$SQL = "SELECT * FROM $TableName as a 
        JOIN tbljoactivity as b ON a.services_id = b.services_id 
        JOIN tbljoborder as c ON b.jo_id = c.jo_id 
        JOIN tbldebtur as d ON b.bill_to = d.CUDEBTUR_FIN ";
        

if ($FNama) 
	if (strlen($WHERE)) $WHERE .= " AND "." a.services_name like '".$FNama."%'";
	else $WHERE .= " a.services_name like '%".$FNama."%'";	
if ($FCode) 
	if (strlen($WHERE)) $WHERE .= " AND "." a.services_code like '".$FCode."%'";
	else $WHERE .= " a.services_code like '%".$FCode."%'";

if (strlen($WHERE))	
{
  $WHERE = " WHERE b.tax_rate like '%".$taxRateSel."%' AND b.bill_nd = 'set' AND b.nd_status <> 'created' AND b.curr = '".$curr."' AND c.jo_id = '".$jo_id."' AND bill_to = '".$debtur_fin."' AND ".$WHERE;
}
	
else 
{
  $WHERE = " WHERE b.tax_rate like '%".$taxRateSel."%' AND b.bill_nd = 'set' AND b.nd_status <> 'created' AND b.curr = '".$curr."' AND c.jo_id = '".$jo_id."' AND bill_to = '".$debtur_fin."' ";
}

$SQL = $SQL.$WHERE. " GROUP BY a.services_id ";


$WHERE = "";

$SQLCount = "SELECT count(*) FROM $TableName as a 
        JOIN tbljoactivity as b ON a.services_id = b.services_id 
        JOIN tbljoborder as c ON b.jo_id = c.jo_id ";

if ($FNama) 
	if (strlen($WHERE)) $WHERE .= " AND "." a.services_name like '".$FNama."%'";
	else $WHERE .= " a.services_name like '%".$FNama."%'";	
if ($FCode) 
	if (strlen($WHERE)) $WHERE .= " AND "." a.services_code like '".$FCode."%'";
	else $WHERE .= " a.services_code like '%".$FCode."%'";

	if (strlen($WHERE))	
	{
	  $WHERE = " WHERE b.tax_rate like '%".$taxRateSel."%' AND b.bill_nd = 'set' AND b.nd_status <> 'created' AND b.curr = '".$curr."' AND c.jo_id = '".$jo_id."' AND ".$WHERE;
	}
	
	else 
	{
	  $WHERE = " WHERE b.tax_rate like '%".$taxRateSel."%' AND b.bill_nd = 'set' AND b.nd_status <> 'created' AND b.curr = '".$curr."' AND c.jo_id = '".$jo_id."' ";
	}
	
	
$SQLCount = $SQLCount.$WHERE. " GROUP BY a.services_id ";


//******* SHOW FORM CONTENT *********

//$PageNum = 1;
//$RecCnt = $DBConnection->dbc->get_var($SQLCount) ; 
//if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");
//Default value
if (!isset($_GET)) $_GET=&$HTTP_GET_VARS ;
if (isset($_GET['PageNum'])) {
  $PageNum = $_GET['PageNum'] ;
} else {
    $PageNum = 1 ;
}

//Default value
if (isset($_GET['RecCnt'])) {
  $RecCnt = intval($_GET['RecCnt']) ;
} else {
    $RecCnt = -1 ;
} 


//GET Kurs

$SQLGetKurs = "SELECT * FROM ais_kurssi WHERE curr = 'USD' ORDER BY tglbkt DESC";
$ResultGetKurs  = $DBConnection->dbc->get_row($SQLGetKurs,ARRAY_A);   

$kursUSD = $ResultGetKurs['rate'];


$SQLGetKursTax = "SELECT * FROM ais_kurspjk WHERE curr = 'USD' ORDER BY tglbkt DESC";
$ResultGetKursTax  = $DBConnection->dbc->get_row($SQLGetKursTax,ARRAY_A);   

$kursUSDTax = $ResultGetKursTax['rate'];



//END GET Kurs
//echo $SQL;

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$RecCnt = $TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ; 
$TBS->Show();



?>
